package com.lj.controller;

import com.lj.pojo.ClientProjectljKey;
import com.lj.pojo.Pclient;
import com.lj.service.PclientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping("/pClient")
public class PclientAction {
    @Autowired
    PclientService pclientService;
    @RequestMapping("/select")
    public String select(String id, HttpServletRequest request){
       List<Pclient> pclients= pclientService.select(id);
       request.setAttribute("pClients",pclients);
       return "client/pClientView";
    }
    @RequestMapping("/update")
    public String update(RedirectAttributes attributes,String clientId, String clientPassword, String clientName, String clientSex, String clientPhone){
        int nums= pclientService.update(clientId,clientPassword,clientName,clientSex,clientPhone);
        attributes.addAttribute("id",clientId);
        return "redirect:/pClient/select.action";
    }
    @RequestMapping("/selectProject")
    public String selectProject(String id,HttpServletRequest request){
        List<ClientProjectljKey> clientProjectljKeys=pclientService.selectProject(id);
        request.setAttribute("clientProject",clientProjectljKeys);
        return "client/pClientProjectView";
    }
}
